// 创建router实例
import { createRouter, createWebHashHistory } from 'vue-router'
import Layout from '@/views/layout/index.vue'
import Home from '@/views/home/index.vue'

export default createRouter({
  // 模式 hash history
  history: createWebHashHistory(),

  scrollBehavior(to, from, savedPosition) {
    // 希望路由切换时  能够让关东条回到顶部 => 人资
    // 233 344
    // vue-router 4 的语法(top: 0) => vue3
    // vue-router 3 的语法(y: 0) => vue2
    return {
      top: 0,
    }
  },
  // scrollBehavior:()=>{
  //   return {
  //     top: 0,
  //   }
  // },
  routes: [
    // layout 架子
    {
      path: '/',
      component: Layout,
      children: [
        {
          path: '',
          component: Home,
        },
        // 一级分类
        {
          path: '/category/:id',
          component: () => import('@/views/category/index.vue'),
        },
        // 二级分类
        {
          path: '/category/sub/:id',
          component: () => import('@/views/category/sub.vue'),
        },

        // 商品详情页
        {
          path: '/goods/:id',
          component: () => import('@/views/goods/index.vue'),
        },
      ],
    },
    // login 架子
    {
      path: '/login',
      component: () => import('@/views/login/index.vue'),
    },

    //测试专用路由
    {
      path: '/playground',
      component: () => import('@/views/playground/index.vue'),
    },
  ],
})
